package com.cby.android.sample.adapter

import android.os.Build
import android.widget.ImageView
import androidx.annotation.RequiresApi
import com.cby.android.library.ext.load
import com.cby.android.sample.R
import com.cby.android.sample.activities.openWebPage
import com.cby.android.sample.bean.tianxing.TXWxNewArticleBean
import com.chad.library.adapter.base.BaseQuickAdapter
import com.chad.library.adapter.base.viewholder.BaseViewHolder

/**
 * 首页-文章列表的适配器
 *
 * @constructor
 */
class TxWxNewArticleAdapter() : BaseQuickAdapter<TXWxNewArticleBean, BaseViewHolder>(R.layout.tx_item_article){


    @RequiresApi(Build.VERSION_CODES.LOLLIPOP)
    override fun convert(holder: BaseViewHolder, item: TXWxNewArticleBean) {
        item.apply {
            holder.setText(R.id.tv_item_description, description)
            holder.setText(R.id.tv_item_title, item.title)
            holder.setText(R.id.tv_item_type, type)
            holder.setText(R.id.item_home_date, ctime)
            val imageview = holder.getView<ImageView>(R.id.iv_item_pic)
            imageview.load(picUrl, R.drawable.awkward)
        }

        holder.itemView.setOnClickListener{
            val url = item.url.replace("&amp;","&")
            openWebPage(context, title = item.title, url = url)
        }
    }
}